package com.woniuxy.car.commodity.service.core.controller;


import com.woniuxy.car.commodity.service.core.dto.CommodityPicsDto;
import com.woniuxy.car.commodity.service.core.entity.Commodity;
import com.woniuxy.car.commodity.service.core.entity.CommodityParam;
import com.woniuxy.car.commodity.service.core.entity.CommodityPics;
import com.woniuxy.car.commodity.service.core.service.ICommodityPicsService;
import com.woniuxy.common.api.CommonResult;
import com.woniuxy.common.api.enums.ResultCode;
import com.woniuxy.common.exception.BusinessException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 商品轮播图 前端控制器
 * </p>
 *
 * @author awz
 * @since 2022-03-01
 */
@Api(tags = "商品图片接口")
@RestController
@RequestMapping("/commodity/commodity-pics")
public class CommodityPicsController {

    @Autowired(required = false)
    ICommodityPicsService commodityPicsService;

    @ApiOperation("根据商品id查询图片")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commodityId", value = "商品id")
    })
    @GetMapping("/{commodityId}")
    public CommonResult<CommodityParam> getPicsById(@PathVariable("commodityId") Integer commodityId){

        try {
            List<CommodityPics> commodityPicsList = commodityPicsService.findPicsById(commodityId);
            return CommonResult.success(commodityPicsList);
        }catch (BusinessException e){
            return CommonResult.failure(ResultCode.FAILED.getCode(),e.getMessage());
        }
    }

}
